﻿using Models.Common;
using Models.MVC;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Web.Filters;

namespace Web.Controllers.MVC
{
    [MvcAuthentication]
    public class CommonsController : Controller
    {
        public ActionResult BillDetailsFailList(int BillDetailsID,int BillNameID)
        {
            ViewBag.ID = BillDetailsID;
            ViewBag.BillNameID = BillNameID;
            return View();
        }
        [HttpPost]
        public string BillDetailsFailListAsync(int BillDetailsID,int BillNameID)
        {
            GridResult result = new GridResult();
            SqlParameter[] parameters = {
                                          new SqlParameter("@BillNameID",SqlDbType.Int),
                                          new SqlParameter("@BillDetailsID",SqlDbType.Int),
            };
            parameters[0].Value = BillNameID;
            parameters[1].Value = BillDetailsID;
            DataSet ds = FreeADO.DBUtility.DbHelperSQL.RunProcedure("SP_QueryBillDetailsFailList", parameters, "aaa", 3000);
            result.count = Convert.ToInt32(ds.Tables[0].Rows[0]["count"]);
            result.data = ds.Tables[1];
            result.totalRow = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(Newtonsoft.Json.JsonConvert.SerializeObject(ds.Tables[2]))[0];
            return Newtonsoft.Json.JsonConvert.SerializeObject(result);
        }
        public ActionResult BillDetailsFailEdit(int BillNameID,int BillDetailsID, int ID = 0)
        {
            DataTable dt = FreeADO.DBUtility.DbHelperSQL.Query(@"
select a.*
FROM BillDetailsFail as a 
WHERE a.ID=" + ID).Tables[0];
            ViewBag.BillDetailsID = BillDetailsID;
            ViewBag.BillNameID = BillNameID;
            ViewBag.ID = ID;
            ViewBag.Qty = 0;
            ViewBag.GoodsID = 0;
            if (dt.Rows.Count > 0)
            {
                ViewBag.Qty = dt.Rows[0]["Qty"].ToString();
                ViewBag.GoodsID = dt.Rows[0]["GoodsID"].ToString();
            }

            DataTable dtg = FreeADO.DBUtility.DbHelperSQL.Query(@"
declare @BillNameID int=" + BillNameID + ",@BillDetailsID int=" + BillDetailsID + @"
IF( @BillNameID=3 )
BEGIN
	select GoodsID,Goods.Name as GoodsName 
        from BillBOM inner join Goods on BillBOM.GoodsID=goods.ID
	where BillNameID=@BillNameID and BillID=(select c.JiHuaOrderID
	from BillDetails3 as a inner join BillProcedures3 as b on a.BillProcedureID =b.ID
			inner join BillIndex3 as c on b.BillIndexID=c.ID
	where a.ID=@BillDetailsID)
END
ELSE IF( @BillNameID=6 )
BEGIN
	select GoodsID,Goods.Name as GoodsName 
    from BillBOM inner join Goods on BillBOM.GoodsID=goods.ID
	where BillNameID=@BillNameID and BillID=(select c.JiHuaOrderID
	from BillDetails6 as a inner join BillProcedures6 as b on a.BillProcedureID =b.ID
		inner join BillIndex6 as c on b.BillIndexID=c.ID
	where a.ID=@BillDetailsID)
END

").Tables[0];
            string g = "";
            foreach (DataRow item in dtg.Rows)
            {
                g = g + @"<option value=""" + item["GoodsID"].ToString() + @""">" + item["GoodsName"].ToString() + @"</option>";
            }
            ViewBag.Goods = g;

            return View();
        }
        [HttpPost]
        public ActionResult BillDetailsFailEditAsync(int BillNameID, int BillDetailsID, int GoodsID, int Qty, int ID)
        {
            Result<string> result = new Result<string>();
            try
            {
                if (ID == 0)
                {
                    if (Convert.ToInt32(FreeADO.DBUtility.DbHelperSQL.GetSingle("select count(*) from BillDetailsFail where BillNameID=" + BillNameID + " and BillDetailsID=" + BillDetailsID + " and GoodsID=" + GoodsID)) > 0)
                    {
                        result.Type = AjaxResultType.Error;
                        result.Content = "列表中已存在此原料"; 
                        return Json(result);
                    }
                    FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillDetailsFail]
           ([BillNameID]
           ,[BillDetailsID]
           ,[GoodsID]
           ,[Qty])
     VALUES
           (
'" + BillNameID + @"',
'" + BillDetailsID + @"',
'" + GoodsID + @"',
'" + Qty + @"'
)
");
                    result.Type = AjaxResultType.Success;
                    result.Content = "成功";
                    result.Data = "成功";
                }
                else
                {
                    if (Convert.ToInt32(FreeADO.DBUtility.DbHelperSQL.GetSingle("select count(*) from BillDetailsFail where BillNameID=" + BillNameID + " and BillDetailsID=" + BillDetailsID + " and GoodsID=" + GoodsID + " and ID<>" + ID)) > 0)
                    {
                        result.Type = AjaxResultType.Error;
                        result.Content = "列表中已存在此原料";
                        return Json(result);
                    }

                    FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
UPDATE [dbo].[BillDetailsFail]
   SET [GoodsID] = '" + GoodsID + @"'
      ,[Qty] = '" + Qty + @"'
 WHERE ID=" + ID + @"
");
                    result.Type = AjaxResultType.Success;
                    result.Content = "成功";
                    result.Data = "成功";
                }
            }
            catch (Exception e)
            {

                result.Type = AjaxResultType.Error;
                result.Content = e.Message;
                result.Data = e.Message;
            }
            return Json(result);
        }
        [HttpPost]
        public ActionResult BillDetailsFailDelAsync(string IDs)
        {
            Result<string> result = new Result<string>();
            try
            {

                FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"Delete BillDetailsFail where ID in (" + IDs + @")");
                result.Type = AjaxResultType.Success;
                result.Content = "成功";
                result.Data = "成功";
            }
            catch (Exception e)
            {

                result.Type = AjaxResultType.Error;
                result.Content = e.Message;
                result.Data = e.Message;
            }
            return Json(result);
        }

        public ActionResult JiHuaOrderList( int BillNameID)
        {
            ViewBag.BillNameID = BillNameID;
            return View();
        }
        [HttpPost]
        public string JiHuaOrderListAsync(int BillNameID, int PageIndex = 1, int PageSize = 1000000000, string Search = "")
        {
            GridResult result = new GridResult();
            SqlParameter[] parameters = {
                                          new SqlParameter("@BillNameID",SqlDbType.Int),
                                          new SqlParameter("@PageIndex",SqlDbType.Int),
                                          new SqlParameter("@PageSize",SqlDbType.Int),
                                          new SqlParameter("@Search",SqlDbType.NVarChar,4000),
            };
            parameters[0].Value = BillNameID;
            parameters[1].Value = PageIndex;
            parameters[2].Value = PageSize;
            parameters[3].Value = Search;
            DataSet ds = FreeADO.DBUtility.DbHelperSQL.RunProcedure("SP_QueryJiHuaOrderList", parameters, "aaa", 3000);
            result.count = Convert.ToInt32(ds.Tables[0].Rows[0]["count"]);
            result.data = ds.Tables[1];
            result.totalRow = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(Newtonsoft.Json.JsonConvert.SerializeObject(ds.Tables[2]))[0];
            return Newtonsoft.Json.JsonConvert.SerializeObject(result);
        }
        public ActionResult JiHuaOrderEdit(int BillNameID, int ID = 0)
        {
            if (BillNameID == 3)
            {
                ViewBag.JiHuaQtyName = "计划数量";
            }
            else
            {
                ViewBag.JiHuaQtyName = "投产数量";
            }
            ViewBag.BillNameID = BillNameID;
            JiHuaOrderModel m = new JiHuaOrderModel();
            if (ID>0)
            {
                m = Common.Common.GetJiHuaOrderModel(ID, BillNameID);
            }
            ViewBag.model = m;

            DataTable ddt = FreeADO.DBUtility.DbHelperSQL.Query("select * from DengJi").Tables[0];
            string ds = "";
            foreach (DataRow item in ddt.Rows)
            {
                ds = ds + @"<option value=""" + item["Name"].ToString() + @""">" + item["Name"].ToString() + @"</option>";
            }
            ViewBag.DengJi = ds;

            return View();
        }
        [HttpPost]
        public ActionResult JiHuaOrderEditAsync(JiHuaOrderModel m)
        {
            Result<string> result = new Result<string>();
            try
            {
                if (m.ID == 0)
                {
                    m.ID = Convert.ToInt32(FreeADO.DBUtility.DbHelperSQL.GetSingle(@"
INSERT INTO [dbo].[PlannedOrder]
           ([BillNameID]
           ,[Code]
           ,[GoodsID]
           ,[Number]
           ,[HeTongCode]
           ,[OrderDate]
           ,[XuFangDaiHao]
           ,[DengJi]
           ,[WaiXing]
           ,[HeTongQty]
           ,[JiHuaQty]
           ,[JiaoFuDate]
           ,[GuiFanHao]
           ,[JianZhiYanShou]
           ,[WenJianBianHao]
           ,[QiTa]
           ,[IsDelete])
     VALUES
           ('" +(m.BillNameID )+ @"'
           ,'" +(m.Code == null ? "" : m.Code) + @"'
           ,'" +(m.GoodsID) + @"'
           ,'" +(m.Number == null ? "" : m.Number) + @"'
           ,'" +(m.HeTongCode == null ? "" : m.HeTongCode) + @"'
           ,'" +(m.OrderDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : m.OrderDate) + @"'
           ,'" +(m.XuFangDaiHao == null ? "" : m.XuFangDaiHao )+ @"'
           ,'" +(m.DengJi == null ? "" : m.DengJi )+ @"'
           ,'" +(m.WaiXing == null ? "" : m.WaiXing )+ @"'
           ,'" +(m.HeTongQty )+ @"'
           ,'" +(m.JiHuaQty) + @"'
           ,'" +(m.JiaoFuDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : m.JiaoFuDate) + @"'
           ,'" +(m.GuiFanHao == null ? "" : m.GuiFanHao) + @"'
           ,'" +(m.JianZhiYanShou == null ? "" : m.JianZhiYanShou )+ @"'
           ,'" +(m.WenJianBianHao == null ? "" : m.WenJianBianHao )+ @"'
           ,'" +(m.QiTa == null ? "" : m.QiTa )+ @"'
           ,'0');
select isnull(SCOPE_IDENTITY(),0)
"));
                    if (m.ID > 0)
                    {
                        if (m.ZhuoGoodsID > 0)
                        {
                            FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'1'
           ,'" + m.ZhuoGoodsID + @"'
           ,'" + m.ZhuoQty + @"'
           ,'" + m.ZhuoLingQty + @"'
           ,'" + (m.ZhuoHuoYuanHao == null ? "" : m.ZhuoHuoYuanHao) + @"'
           ,'" + (m.ZhuoJianYanPiHao == null ? "" : m.ZhuoJianYanPiHao) + @"'
           ,'" + (m.ZhuoZhiZhaoChangShang == null ? "" : m.ZhuoZhiZhaoChangShang) + @"'
           ,'" + (m.ZhuoXinPianMianJi == null ? "" : m.ZhuoXinPianMianJi) + @"'
           ,'" + (m.ZhuoZhengMianJinShu == null ? "" : m.ZhuoZhengMianJinShu) + @"'
           ,'" + (m.ZhuoBeiMianJinShu == null ? "" : m.ZhuoBeiMianJinShu) + @"'
)");
                        }
                        if (m.MaoGoodsID > 0)
                        {
                            FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'2'
           ,'" + m.MaoGoodsID + @"'
           ,'" + m.MaoQty + @"'
           ,'" + m.MaoLingQty + @"'
           ,'" + (m.MaoHuoYuanHao == null ? "" : m.MaoHuoYuanHao) + @"'
           ,'" + (m.MaoJianYanPiHao == null ? "" : m.MaoJianYanPiHao) + @"'
           ,'" + (m.MaoZhiZhaoChangShang == null ? "" : m.MaoZhiZhaoChangShang) + @"'
           ,'" + (m.MaoXinPianMianJi == null ? "" : m.MaoXinPianMianJi) + @"'
           ,'" + (m.MaoZhengMianJinShu == null ? "" : m.MaoZhengMianJinShu) + @"'
           ,'" + (m.MaoBeiMianJinShu == null ? "" : m.MaoBeiMianJinShu) + @"'
)");
                        }

                        if (m.Xin1GoodsID > 0)
                        {
                            FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin1GoodsID + @"'
           ,'" + m.Xin1Qty + @"'
           ,'" + m.Xin1LingQty + @"'
           ,'" + (m.Xin1HuoYuanHao == null ? "" : m.Xin1HuoYuanHao) + @"'
           ,'" + (m.Xin1JianYanPiHao == null ? "" : m.Xin1JianYanPiHao) + @"'
           ,'" + (m.Xin1ZhiZhaoChangShang == null ? "" : m.Xin1ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin1XinPianMianJi == null ? "" : m.Xin1XinPianMianJi) + @"'
           ,'" + (m.Xin1ZhengMianJinShu == null ? "" : m.Xin1ZhengMianJinShu) + @"'
           ,'" + (m.Xin1BeiMianJinShu == null ? "" : m.Xin1BeiMianJinShu) + @"'
)");
                        }
                        if (m.Xin2GoodsID > 0)
                        {
                            FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin2GoodsID + @"'
           ,'" + m.Xin2Qty + @"'
           ,'" + m.Xin2LingQty + @"'
           ,'" + (m.Xin2HuoYuanHao == null ? "" : m.Xin2HuoYuanHao) + @"'
           ,'" + (m.Xin2JianYanPiHao == null ? "" : m.Xin2JianYanPiHao) + @"'
           ,'" + (m.Xin2ZhiZhaoChangShang == null ? "" : m.Xin2ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin2XinPianMianJi == null ? "" : m.Xin2XinPianMianJi) + @"'
           ,'" + (m.Xin2ZhengMianJinShu == null ? "" : m.Xin2ZhengMianJinShu) + @"'
           ,'" + (m.Xin2BeiMianJinShu == null ? "" : m.Xin2BeiMianJinShu) + @"'
)");
                        }
                        if (m.Xin3GoodsID > 0)
                        {
                            FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin3GoodsID + @"'
           ,'" + m.Xin3Qty + @"'
           ,'" + m.Xin3LingQty + @"'
           ,'" + (m.Xin3HuoYuanHao == null ? "" : m.Xin3HuoYuanHao) + @"'
           ,'" + (m.Xin3JianYanPiHao == null ? "" : m.Xin3JianYanPiHao) + @"'
           ,'" + (m.Xin3ZhiZhaoChangShang == null ? "" : m.Xin3ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin3XinPianMianJi == null ? "" : m.Xin3XinPianMianJi) + @"'
           ,'" + (m.Xin3ZhengMianJinShu == null ? "" : m.Xin3ZhengMianJinShu) + @"'
           ,'" + (m.Xin3BeiMianJinShu == null ? "" : m.Xin3BeiMianJinShu) + @"'
)");
                        }
                        if (m.Xin4GoodsID > 0)
                        {
                            FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin4GoodsID + @"'
           ,'" + m.Xin4Qty + @"'
           ,'" + m.Xin4LingQty + @"'
           ,'" + (m.Xin4HuoYuanHao == null ? "" : m.Xin4HuoYuanHao) + @"'
           ,'" + (m.Xin4JianYanPiHao == null ? "" : m.Xin4JianYanPiHao) + @"'
           ,'" + (m.Xin4ZhiZhaoChangShang == null ? "" : m.Xin4ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin4XinPianMianJi == null ? "" : m.Xin4XinPianMianJi) + @"'
           ,'" + (m.Xin4ZhengMianJinShu == null ? "" : m.Xin4ZhengMianJinShu) + @"'
           ,'" + (m.Xin4BeiMianJinShu == null ? "" : m.Xin4BeiMianJinShu) + @"'
)");
                        }
                        if (m.Xin5GoodsID > 0)
                        {
                            FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin5GoodsID + @"'
           ,'" + m.Xin5Qty + @"'
           ,'" + m.Xin5LingQty + @"'
           ,'" + (m.Xin5HuoYuanHao == null ? "" : m.Xin5HuoYuanHao) + @"'
           ,'" + (m.Xin5JianYanPiHao == null ? "" : m.Xin5JianYanPiHao) + @"'
           ,'" + (m.Xin5ZhiZhaoChangShang == null ? "" : m.Xin5ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin5XinPianMianJi == null ? "" : m.Xin5XinPianMianJi) + @"'
           ,'" + (m.Xin5ZhengMianJinShu == null ? "" : m.Xin5ZhengMianJinShu) + @"'
           ,'" + (m.Xin5BeiMianJinShu == null ? "" : m.Xin5BeiMianJinShu) + @"'
)");
                        }
                        if (m.Xin6GoodsID > 0)
                        {
                            FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin6GoodsID + @"'
           ,'" + m.Xin6Qty + @"'
           ,'" + m.Xin6LingQty + @"'
           ,'" + (m.Xin6HuoYuanHao == null ? "" : m.Xin6HuoYuanHao) + @"'
           ,'" + (m.Xin6JianYanPiHao == null ? "" : m.Xin6JianYanPiHao) + @"'
           ,'" + (m.Xin6ZhiZhaoChangShang == null ? "" : m.Xin6ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin6XinPianMianJi == null ? "" : m.Xin6XinPianMianJi) + @"'
           ,'" + (m.Xin6ZhengMianJinShu == null ? "" : m.Xin6ZhengMianJinShu) + @"'
           ,'" + (m.Xin6BeiMianJinShu == null ? "" : m.Xin6BeiMianJinShu) + @"'
)");
                        }

                    }
                    else
                    {
                        result.Type = AjaxResultType.Error;
                        result.Content = "失败";
                        result.Data = "失败";
                    }
                    result.Type = AjaxResultType.Success;
                    result.Content = "成功";
                    result.Data = m.ID.ToString();
                }
                else
                {
                    FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
UPDATE [dbo].[PlannedOrder]
   SET [BillNameID] = '" + m.BillNameID + @"'
      ,[Code] = '" + (m.Code == null ? "" : m.Code) + @"'
      ,[GoodsID] = '" + m.GoodsID + @"'
      ,[Number] = '" + (m.Number == null ? "" : m.Number) + @"'
      ,[HeTongCode] = '" + (m.HeTongCode == null ? "" : m.HeTongCode) + @"'
      ,[OrderDate] = '" + (m.OrderDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : m.OrderDate) + @"'
      ,[XuFangDaiHao] = '" + (m.XuFangDaiHao == null ? "" : m.XuFangDaiHao) + @"'
      ,[DengJi] = '" + (m.DengJi == null ? "" : m.DengJi) + @"'
      ,[WaiXing] = '" + (m.WaiXing == null ? "" : m.WaiXing) + @"'
      ,[HeTongQty] = '" + m.HeTongQty + @"'
      ,[JiHuaQty] = '" + m.JiHuaQty + @"'
      ,[JiaoFuDate] = '" + (m.JiaoFuDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : m.JiaoFuDate) + @"'
      ,[GuiFanHao] = '" + (m.GuiFanHao == null ? "" : m.GuiFanHao) + @"'
      ,[JianZhiYanShou] = '" + (m.JianZhiYanShou == null ? "" : m.JianZhiYanShou) + @"'
      ,[WenJianBianHao] = '" + (m.WenJianBianHao == null ? "" : m.WenJianBianHao) + @"'
      ,[QiTa] = '" + (m.QiTa == null ? "" : m.QiTa) + @"'
 WHERE ID=" + m.ID + @";
delete BillBom where BillNameID=" + m.BillNameID + @" and BillID=" + m.ID + @";
");
                    if (m.ZhuoGoodsID > 0)
                    {
                        FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'1'
           ,'" + m.ZhuoGoodsID + @"'
           ,'" + m.ZhuoQty + @"'
           ,'" + m.ZhuoLingQty + @"'
           ,'" + (m.ZhuoHuoYuanHao == null ? "" : m.ZhuoHuoYuanHao) + @"'
           ,'" + (m.ZhuoJianYanPiHao == null ? "" : m.ZhuoJianYanPiHao) + @"'
           ,'" + (m.ZhuoZhiZhaoChangShang == null ? "" : m.ZhuoZhiZhaoChangShang) + @"'
           ,'" + (m.ZhuoXinPianMianJi == null ? "" : m.ZhuoXinPianMianJi) + @"'
           ,'" + (m.ZhuoZhengMianJinShu == null ? "" : m.ZhuoZhengMianJinShu) + @"'
           ,'" + (m.ZhuoBeiMianJinShu == null ? "" : m.ZhuoBeiMianJinShu) + @"'
)");
                    }
                    if (m.MaoGoodsID > 0)
                    {
                        FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'2'
           ,'" + m.MaoGoodsID + @"'
           ,'" + m.MaoQty + @"'
           ,'" + m.MaoLingQty + @"'
           ,'" + (m.MaoHuoYuanHao == null ? "" : m.MaoHuoYuanHao) + @"'
           ,'" + (m.MaoJianYanPiHao == null ? "" : m.MaoJianYanPiHao) + @"'
           ,'" + (m.MaoZhiZhaoChangShang == null ? "" : m.MaoZhiZhaoChangShang) + @"'
           ,'" + (m.MaoXinPianMianJi == null ? "" : m.MaoXinPianMianJi) + @"'
           ,'" + (m.MaoZhengMianJinShu == null ? "" : m.MaoZhengMianJinShu) + @"'
           ,'" + (m.MaoBeiMianJinShu == null ? "" : m.MaoBeiMianJinShu) + @"'
)");
                    }

                    if (m.Xin1GoodsID > 0)
                    {
                        FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin1GoodsID + @"'
           ,'" + m.Xin1Qty + @"'
           ,'" + m.Xin1LingQty + @"'
           ,'" + (m.Xin1HuoYuanHao == null ? "" : m.Xin1HuoYuanHao) + @"'
           ,'" + (m.Xin1JianYanPiHao == null ? "" : m.Xin1JianYanPiHao) + @"'
           ,'" + (m.Xin1ZhiZhaoChangShang == null ? "" : m.Xin1ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin1XinPianMianJi == null ? "" : m.Xin1XinPianMianJi) + @"'
           ,'" + (m.Xin1ZhengMianJinShu == null ? "" : m.Xin1ZhengMianJinShu) + @"'
           ,'" + (m.Xin1BeiMianJinShu == null ? "" : m.Xin1BeiMianJinShu) + @"'
)");
                    }
                    if (m.Xin2GoodsID > 0)
                    {
                        FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin2GoodsID + @"'
           ,'" + m.Xin2Qty + @"'
           ,'" + m.Xin2LingQty + @"'
           ,'" + (m.Xin2HuoYuanHao == null ? "" : m.Xin2HuoYuanHao) + @"'
           ,'" + (m.Xin2JianYanPiHao == null ? "" : m.Xin2JianYanPiHao) + @"'
           ,'" + (m.Xin2ZhiZhaoChangShang == null ? "" : m.Xin2ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin2XinPianMianJi == null ? "" : m.Xin2XinPianMianJi) + @"'
           ,'" + (m.Xin2ZhengMianJinShu == null ? "" : m.Xin2ZhengMianJinShu) + @"'
           ,'" + (m.Xin2BeiMianJinShu == null ? "" : m.Xin2BeiMianJinShu) + @"'
)");
                    }
                    if (m.Xin3GoodsID > 0)
                    {
                        FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin3GoodsID + @"'
           ,'" + m.Xin3Qty + @"'
           ,'" + m.Xin3LingQty + @"'
           ,'" + (m.Xin3HuoYuanHao == null ? "" : m.Xin3HuoYuanHao) + @"'
           ,'" + (m.Xin3JianYanPiHao == null ? "" : m.Xin3JianYanPiHao) + @"'
           ,'" + (m.Xin3ZhiZhaoChangShang == null ? "" : m.Xin3ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin3XinPianMianJi == null ? "" : m.Xin3XinPianMianJi) + @"'
           ,'" + (m.Xin3ZhengMianJinShu == null ? "" : m.Xin3ZhengMianJinShu) + @"'
           ,'" + (m.Xin3BeiMianJinShu == null ? "" : m.Xin3BeiMianJinShu) + @"'
)");
                    }
                    if (m.Xin4GoodsID > 0)
                    {
                        FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin4GoodsID + @"'
           ,'" + m.Xin4Qty + @"'
           ,'" + m.Xin4LingQty + @"'
           ,'" + (m.Xin4HuoYuanHao == null ? "" : m.Xin4HuoYuanHao) + @"'
           ,'" + (m.Xin4JianYanPiHao == null ? "" : m.Xin4JianYanPiHao) + @"'
           ,'" + (m.Xin4ZhiZhaoChangShang == null ? "" : m.Xin4ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin4XinPianMianJi == null ? "" : m.Xin4XinPianMianJi) + @"'
           ,'" + (m.Xin4ZhengMianJinShu == null ? "" : m.Xin4ZhengMianJinShu) + @"'
           ,'" + (m.Xin4BeiMianJinShu == null ? "" : m.Xin4BeiMianJinShu) + @"'
)");
                    }
                    if (m.Xin5GoodsID > 0)
                    {
                        FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin5GoodsID + @"'
           ,'" + m.Xin5Qty + @"'
           ,'" + m.Xin5LingQty + @"'
           ,'" + (m.Xin5HuoYuanHao == null ? "" : m.Xin5HuoYuanHao) + @"'
           ,'" + (m.Xin5JianYanPiHao == null ? "" : m.Xin5JianYanPiHao) + @"'
           ,'" + (m.Xin5ZhiZhaoChangShang == null ? "" : m.Xin5ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin5XinPianMianJi == null ? "" : m.Xin5XinPianMianJi) + @"'
           ,'" + (m.Xin5ZhengMianJinShu == null ? "" : m.Xin5ZhengMianJinShu) + @"'
           ,'" + (m.Xin5BeiMianJinShu == null ? "" : m.Xin5BeiMianJinShu) + @"'
)");
                    }
                    if (m.Xin6GoodsID > 0)
                    {
                        FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
INSERT INTO [dbo].[BillBOM]
           ([BillNameID]
           ,[BillID]
           ,[Type]
           ,[GoodsID]
           ,[Qty]
           ,[LingQty]
           ,[HuoYuanHao]
           ,[JianYanPiHao]
           ,[ZhiZhaoChangShang]
           ,[XinPianMianJi]
           ,[ZhengMianJinShu]
           ,[BeiMianJinShu])
     VALUES
           ('" + m.BillNameID + @"'
           ,'" + m.ID + @"'
           ,'3'
           ,'" + m.Xin6GoodsID + @"'
           ,'" + m.Xin6Qty + @"'
           ,'" + m.Xin6LingQty + @"'
           ,'" + (m.Xin6HuoYuanHao == null ? "" : m.Xin6HuoYuanHao) + @"'
           ,'" + (m.Xin6JianYanPiHao == null ? "" : m.Xin6JianYanPiHao) + @"'
           ,'" + (m.Xin6ZhiZhaoChangShang == null ? "" : m.Xin6ZhiZhaoChangShang) + @"'
           ,'" + (m.Xin6XinPianMianJi == null ? "" : m.Xin6XinPianMianJi) + @"'
           ,'" + (m.Xin6ZhengMianJinShu == null ? "" : m.Xin6ZhengMianJinShu) + @"'
           ,'" + (m.Xin6BeiMianJinShu == null ? "" : m.Xin6BeiMianJinShu) + @"'
)");
                    }

                    result.Type = AjaxResultType.Success;
                    result.Content = "成功";
                    result.Data = m.ID.ToString();
                }
            }
            catch (Exception e)
            {

                result.Type = AjaxResultType.Error;
                result.Content = e.Message;
                result.Data = e.Message;
            }
            return Json(result);
        }
        [HttpPost]
        public ActionResult JiHuaOrderDelAsync(string IDs)
        {
            Result<string> result = new Result<string>();
            try
            {

                FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"Update PlannedOrder set IsDelete=1 where ID in (" + IDs + @")");
                result.Type = AjaxResultType.Success;
                result.Content = "成功";
                result.Data = "成功";
            }
            catch (Exception e)
            {

                result.Type = AjaxResultType.Error;
                result.Content = e.Message;
                result.Data = e.Message;
            }
            return Json(result);
        }
        [HttpPost]
        public ActionResult JiHuaOrderModelAsync(int GoodsID,int BillNameID)
        {
            Result<JiHuaOrderModel> result = new Result<JiHuaOrderModel>();
            try
            {
                result.Data = Common.Common.GetJiHuaOrderModelForGoods(GoodsID, BillNameID);
                result.Type = AjaxResultType.Success;
                result.Content = "成功";
            }
            catch (Exception e)
            {

                result.Type = AjaxResultType.Error;
                result.Content = e.Message;
                result.Data = new JiHuaOrderModel()                           ;
            }
            return Json(result);
        }
        public ActionResult JiHuaOrderSelect(string Back = "", int BillNameID = 0)
        {
            ViewBag.Back = Back;
            ViewBag.BillNameID = BillNameID;
            return View();
        }
        [HttpPost]
        public string JiHuaOrderGoodsListAsync(int BillNameID, int ID)
        {
            GridResult result = new GridResult();
            DataTable dt = FreeADO.DBUtility.DbHelperSQL.Query(@"
select a.ID,a.BillNameID,a.BillID,a.Type,a.GoodsID,b.Name as GoodsName,b.Code as GoodsCode,b.Model as GoodsModel
		,a.Qty,a.LingQty,a.HuoYuanHao,a.JianYanPiHao,a.ZhiZhaoChangShang,a.XinPianMianJi,a.ZhengMianJinShu,a.BeiMianJinShu
from BillBom as a inner join Goods as b on a.GoodsID=b.ID
where a.BillID=" + ID + " and BillNameID=" + BillNameID + @"
").Tables[0];
            result.count = 0;
            result.data = dt;
            result.totalRow = new Dictionary<string, string>();
            return Newtonsoft.Json.JsonConvert.SerializeObject(result);
        }

        public ActionResult BillProDetails(int BillNameID = 0,int ProID=0,int Type=1)
        {
            ViewBag.BillNameID = BillNameID;
            ViewBag.ProID = ProID;
            ViewBag.Type = Type;
            BillProDetailsModel m = new BillProDetailsModel();
            if (BillNameID>0 && ProID>0)
            {
                DataTable dt = FreeADO.DBUtility.DbHelperSQL.Query("select * from BillProDetails where BillNameID=" + BillNameID + " and BillProID=" + ProID).Tables[0];
                if (dt.Rows.Count>0)
                {
                    m = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Models.MVC.BillProDetailsModel>>(Newtonsoft.Json.JsonConvert.SerializeObject(dt))[0];
                }
            }
            ViewBag.model = m;
            switch (Type)
            {
                case 1:
                    return View("BillProDetails1");
                case 2:
                    return View("BillProDetails2");
                case 3:
                    return View("BillProDetails3");
                case 4:
                    return View("BillProDetails4");
                case 5:
                    return View("BillProDetails5");
                case 6:
                    return View("BillProDetails6");
                default:
                    break;
            }
            return View("BillProDetails1");
        }
        [HttpPost]
        public ActionResult BillProDetailsAsync(BillProDetailsModel m)
        {
            Result<string> result = new Result<string>();
            try
            {
                if (m.ID == 0)
                {
                    m.ID = Convert.ToInt32(FreeADO.DBUtility.DbHelperSQL.GetSingle(@"
INSERT INTO [dbo].[BillProDetails]
           ([BillNameID]
           ,[BillProID]
           ,[Field1]
           ,[Field2]
           ,[Field3]
           ,[Field4]
           ,[Field5]
           ,[Field6]
           ,[Field7]
           ,[Field8]
           ,[Field9]
           ,[Field10]
           ,[Field11]
           ,[Field12]
           ,[Field13]
           ,[Field14]
           ,[Field15]
           ,[Field16]
           ,[Field17]
           ,[Field18]
           ,[Field19]
           ,[Field20]
           ,[Field21]
           ,[Field22]
           ,[Field23]
           ,[Field24]
           ,[Field25]
           ,[Field26]
           ,[Field27]
           ,[Field28]
           ,[Field29]
           ,[Field30]
           ,[Field31]
           ,[Field32]
           ,[Field33]
           ,[Field34]
           ,[Field35]
           ,[Field36]
           ,[Field37]
           ,[Field38]
           ,[Field39]
           ,[Field40]
           ,[Field41]
           ,[Field42]
           ,[Field43]
           ,[Field44]
           ,[Field45]
           ,[Field46]
           ,[Field47]
           ,[Field48]
           ,[Field49]
           ,[Field50])
     VALUES
           ('" + (m.BillNameID )+ @"'
           ,'" +(m.BillProID) + @"'
           ,'" + (m.Field1) + @"'
           ,'" + (m.Field2) + @"'
           ,'" + (m.Field3) + @"'
           ,'" + (m.Field4) + @"'
           ,'" + (m.Field5) + @"'
           ,'" + (m.Field6) + @"'
           ,'" + (m.Field7) + @"'
           ,'" + (m.Field8) + @"'
           ,'" + (m.Field9) + @"'
           ,'" + (m.Field10) + @"'
           ,'" + (m.Field11) + @"'
           ,'" + (m.Field12) + @"'
           ,'" + (m.Field13) + @"'
           ,'" + (m.Field14) + @"'
           ,'" + (m.Field15) + @"'
           ,'" + (m.Field16) + @"'
           ,'" + (m.Field17) + @"'
           ,'" + (m.Field18) + @"'
           ,'" + (m.Field19) + @"'
           ,'" + (m.Field20) + @"'
           ,'" + (m.Field21) + @"'
           ,'" + (m.Field22) + @"'
           ,'" + (m.Field23) + @"'
           ,'" + (m.Field24) + @"'
           ,'" + (m.Field25) + @"'
           ,'" + (m.Field26) + @"'
           ,'" + (m.Field27) + @"'
           ,'" + (m.Field28) + @"'
           ,'" + (m.Field29) + @"'
           ,'" + (m.Field30) + @"'
           ,'" + (m.Field31) + @"'
           ,'" + (m.Field32) + @"'
           ,'" + (m.Field33) + @"'
           ,'" + (m.Field34) + @"'
           ,'" + (m.Field35) + @"'
           ,'" + (m.Field36) + @"'
           ,'" + (m.Field37) + @"'
           ,'" + (m.Field38) + @"'
           ,'" + (m.Field39) + @"'
           ,'" + (m.Field40) + @"'
           ,'" + (m.Field41) + @"'
           ,'" + (m.Field42) + @"'
           ,'" + (m.Field43) + @"'
           ,'" + (m.Field44) + @"'
           ,'" + (m.Field45) + @"'
           ,'" + (m.Field46) + @"'
           ,'" + (m.Field47) + @"'
           ,'" + (m.Field48) + @"'
           ,'" + (m.Field49) + @"'
           ,'" + (m.Field50) + @"');
select isnull(SCOPE_IDENTITY(),0)
"));
                    
                    result.Type = AjaxResultType.Success;
                    result.Content = "成功";
                    result.Data = "成功";
                }
                else
                {
                    FreeADO.DBUtility.DbHelperSQL.ExecuteSql(@"
UPDATE [dbo].[BillProDetails]
   SET [BillNameID] = '" + m.BillNameID + @"'
      ,[BillProID] = '" + m.BillProID + @"'
      ,[Field1] = '" + m.Field1 + @"'
      ,[Field2] = '" + m.Field2 + @"'
      ,[Field3] = '" + m.Field3 + @"'
      ,[Field4] = '" + m.Field4 + @"'
      ,[Field5] = '" + m.Field5 + @"'
      ,[Field6] = '" + m.Field6 + @"'
      ,[Field7] = '" + m.Field7 + @"'
      ,[Field8] = '" + m.Field8 + @"'
      ,[Field9] = '" + m.Field9 + @"'
      ,[Field10] = '" + m.Field10 + @"'
      ,[Field11] = '" + m.Field11 + @"'
      ,[Field12] = '" + m.Field12 + @"'
      ,[Field13] = '" + m.Field13 + @"'
      ,[Field14] = '" + m.Field14 + @"'
      ,[Field15] = '" + m.Field15 + @"'
      ,[Field16] = '" + m.Field16 + @"'
      ,[Field17] = '" + m.Field17 + @"'
      ,[Field18] = '" + m.Field18 + @"'
      ,[Field19] = '" + m.Field19 + @"'
      ,[Field20] = '" + m.Field20 + @"'
      ,[Field21] = '" + m.Field21 + @"'
      ,[Field22] = '" + m.Field22 + @"'
      ,[Field23] = '" + m.Field23 + @"'
      ,[Field24] = '" + m.Field24 + @"'
      ,[Field25] = '" + m.Field25 + @"'
      ,[Field26] = '" + m.Field26 + @"'
      ,[Field27] = '" + m.Field27 + @"'
      ,[Field28] = '" + m.Field28 + @"'
      ,[Field29] = '" + m.Field29 + @"'
      ,[Field30] = '" + m.Field30 + @"'
      ,[Field31] = '" + m.Field31 + @"'
      ,[Field32] = '" + m.Field32 + @"'
      ,[Field33] = '" + m.Field33 + @"'
      ,[Field34] = '" + m.Field34 + @"'
      ,[Field35] = '" + m.Field35 + @"'
      ,[Field36] = '" + m.Field36 + @"'
      ,[Field37] = '" + m.Field37 + @"'
      ,[Field38] = '" + m.Field38 + @"'
      ,[Field39] = '" + m.Field39 + @"'
      ,[Field40] = '" + m.Field40 + @"'
      ,[Field41] = '" + m.Field41 + @"'
      ,[Field42] = '" + m.Field42 + @"'
      ,[Field43] = '" + m.Field43 + @"'
      ,[Field44] = '" + m.Field44 + @"'
      ,[Field45] = '" + m.Field45 + @"'
      ,[Field46] = '" + m.Field46 + @"'
      ,[Field47] = '" + m.Field47 + @"'
      ,[Field48] = '" + m.Field48 + @"'
      ,[Field49] = '" + m.Field49 + @"'
      ,[Field50] = '" + m.Field50 + @"'
 WHERE ID=" + m.ID + @";
delete BillBom where BillNameID=" + m.BillNameID + @" and BillID=" + m.ID + @";
");
                    result.Type = AjaxResultType.Success;
                    result.Content = "成功";
                    result.Data = "成功";
                }
            }
            catch (Exception e)
            {

                result.Type = AjaxResultType.Error;
                result.Content = e.Message;
                result.Data = e.Message;
            }
            return Json(result);
        }
        public FileResult ProDetailsDown(int BillNameID,int ProID,int Type)
        {
            BillProDetailsModel m = new BillProDetailsModel();
            if (BillNameID > 0 && ProID > 0)
            {
                DataTable dt = FreeADO.DBUtility.DbHelperSQL.Query("select * from BillProDetails where BillNameID=" + BillNameID + " and BillProID=" + ProID).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    m = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Models.MVC.BillProDetailsModel>>(Newtonsoft.Json.JsonConvert.SerializeObject(dt))[0];
                }
            }
            MemoryStream ms = new MemoryStream();
            switch (Type)
            {
                case 1:
                    ms = Common.ExcelTool.BillProDetailsToExcel1(m);
                    break;
                case 2:
                    ms = Common.ExcelTool.BillProDetailsToExcel2(m);
                    break;
                case 3:
                    ms = Common.ExcelTool.BillProDetailsToExcel3(m);
                    break;
                case 4:
                    ms = Common.ExcelTool.BillProDetailsToExcel4(m);
                    break;
                case 5:
                    ms = Common.ExcelTool.BillProDetailsToExcel5(m);
                    break;
                case 6:
                    ms = Common.ExcelTool.BillProDetailsToExcel6(m);
                    break;
                default:
                    break;
            }
            return File(ms, "application/vnd.ms-excel", "首件检验.xls");
        }

    }
}